package api;

public class InternDemo {

    public static void main(String[] args) {

        String str1 = new String("hello").intern();
        String str2 = "hello";
        String str3 = new String("hello").intern();
        String str4 = new String("hello");

        System.out.println(str1 == str2);
        System.out.println(str1 == str3);
        System.out.println(str2 == str4);
        System.out.println(str1 == str4);

        System.out.println("\n------------------------");

        String s1 = new StringBuilder().append("String").append("Test").toString();
        System.out.println(s1.intern() == s1);

        String s2 = new StringBuilder().append("j").append("ava").toString();
        System.out.println(s2.intern() == s2);
    }
}
